// pages/detail3/detail3.js
//文章详情页
const app = getApp()
var landui = require("../../utils/util.js");
var WxParse = require('../../utils/wxParse/wxParse.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    domain: app.globalData.domain,
    trueDomain: app.globalData.trueDomain,
    current_nav: 'toilet',
    info: [],
    list2: [],
    url:'/pages/toilet/detail',
    cid:3
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 文章详情 http://jk.hnla.cn/api/articles/{id}
    landui.common.post({
      module: 'articles/'+ options.id,
      success: function (res) {
        /**
         * * WxParse.wxParse(bindName , type, data,target,imagePadding)
          * 1.bindName绑定的数据名(必填)
          * 2.type可以为html或者md(必填)
          * 3.data为传入的具体数据(必填)
          * 4.target为Page对象,一般为this(必填)
         */
        res.data.content = WxParse.wxParse('content', 'html', res.data.content, that, 5)
        res.data.add_time = res.data.add_time.substring(0,10);
       
        that.setData({
          info:res.data,
          cid:res.data.classify_id
        });
       
        // 相关文章  http://jk.hnla.cn/api/articles?number=3&classify=1
        landui.common.post({
          module: 'articles',
          param: { classify: res.data.classify_id, number: 3},
          success: function (res) {
            var i = 0;
            that.list2 = res.data;
            for (i; i < res.data.length; i++) {
              that.list2[i]['add_time'] = res.data[i].add_time.substring(0, 10)
            }
            that.setData({
              list2: res.data
            })
          },
          fail: function () {
          }
        });
      },
      fail: function () {
      }
    });
   
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})